package com.wandian.audio.adapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mylib.libcore.AppContext;
import com.mylib.libcore.utils.GlideUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.audio.R;
import com.wandian.audio.bean.MusicBean;

import static com.wandian.audio.config.AudioConfig.AUDIO_SELECT_MUSIC_INDEX;

/**
 * @author Administrator
 * @date 2019/12/16-13:32
 * @description AudioCatalogRecycleAdapter
 **/
public class AudioPlayHistoryRecycleAdapter extends BaseQuickAdapter<MusicBean, BaseViewHolder> {

    private int  selectIndex =0;
    public AudioPlayHistoryRecycleAdapter(int layoutResId) {
        super(layoutResId);
        String index = AppContext.getInstance().getAppPreferencesHelper().getKeyValue(AUDIO_SELECT_MUSIC_INDEX);
        if(!UIUtils.isEmpty(index))selectIndex = Integer.parseInt(index);
    }

    @Override
    protected void convert(BaseViewHolder helper, MusicBean item) {
        TextView tv_music_name = helper.getView(R.id.tv_music_name);
        TextView tv_music_author = helper.getView(R.id.tv_music_author);
        ImageView iv_music_bg = helper.getView(R.id.iv_music_bg);
        LinearLayout ll_audio_history = helper.getView(R.id.ll_audio_history);
        tv_music_name.setText(item.getName()+"");
        tv_music_author.setText(item.getNickname()+"");
        GlideUtil.into(mContext,item.getThumb(),iv_music_bg);
        if(selectIndex == helper.getLayoutPosition()){
            ll_audio_history.setBackground(mContext.getResources().getDrawable(R.drawable.button_transparent_two_circle_solid_selector_6));
        }else {
            ll_audio_history.setBackground(mContext.getResources().getDrawable(R.color.white));
        }

    }

}
